Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1671
Summary
Adds
src/services/chain-sync.js— a service that maps decoded escrow events (fromsrc/indexer/decode.js) to idempotent invoice-store mutations and emits the same webhook events the API routes already emit. The indexer wires it in soPOST /api/internal/indexer/runnow applies events to invoice state, not just stores them.src/services/chain-sync.js(new) —applyEvents(events, opts)sorts events by ledger, then dispatches on type:funded→ records the contribution viastore.fund(), emitsinvoice.funding_receivedfunding_target_reached→ emitsinvoice.funded(the status is already flipped bystore.fund()when the final contribution arrives)settled→store.settle(), emitsinvoice.settledrefunded/funding_cancelled→store.cancel(), emitsinvoice.cancelledSet, exportedresetAppliedIdsForTests()for tests)actor: "indexer",action: "invoice.chain_sync",outcome: "success"src/indexer/escrow-indexer.js— afterstore.append([decoded]), callschainSync.applyEvents([decoded])and mergesapplied/ignoredinto the run summary.runOncenow returnsappliedandignoredalongside the existingingested/skipped.src/routes/indexerTrigger.jspasses the extended shape through unchanged, soPOST /api/internal/indexer/runnow reports applied/ignored counts.Acceptance criteria
applyEventsdedupes by event id; testfull replay of the same event list is a no-opassertsapplied: 0on the second call.contractIddoesn't match anyinvoice.escrowContractIdare ignored (unknownContract).fundedrejects when terminal;settledrejects when alreadysettled/cancelled;refunded/funding_cancelledreject whensettled.settled flips status, emits invoice.settled, and writes an audit entry with actor=indexer.runOncereturns{ ingested, skipped, applied, ignored, ... }, passed through bysrc/routes/indexerTrigger.js.Test output
npx jest --runInBand tests/chain-sync.test.jsFiles changed
Note on the upstream
mutatingLimiterregressionupstream/mainat9ac9e4a(merge of #1729) hasReferenceError: mutatingLimiter is not definedatsrc/routes/invoices.js:253— themutatingLimiterexport fromsrc/middleware/rate-limit.js:396isn't imported in that file. That regression blocks every test that loadssrc/app.js.This PR's test file does not load
src/app.js— it requiressrc/services/chain-syncandsrc/data/storedirectly — sonpx jest tests/chain-sync.test.jsruns green regardless. The existingtests/indexerTrigger.test.jsmocksrunOnce, so it is unaffected by the extended response shape.